package com.k8.common.ioc.processorImpl;

import com.k8.common.annotation.Auto;
import com.k8.common.aware.ExtensionAccessorAware;
import com.k8.common.ioc.BeanPostProcessor;
import com.k8.common.factroy.loader.ExtensionAccessor;

@Auto
public class ExtensionAccessorAwarePostProcessor implements BeanPostProcessor {
    ExtensionAccessor extensionAccessor;

    public ExtensionAccessorAwarePostProcessor(ExtensionAccessor extensionAccessor) {
        this.extensionAccessor = extensionAccessor;
    }

    @Override
    public <E> E postProcessBeforeInitialization(E bean, String beanName) {
        if (bean instanceof ExtensionAccessorAware extensionAccessorAware) {
            extensionAccessorAware.setExtensionAccessor(extensionAccessor);
        }
        return bean;
    }
}
